//
//  Care_Animation.m
//  fruitParty
//
//  Created by Moling on 16/9/12.
//  Copyright © 2016年 zuankuangren. All rights reserved.
//

#import "Care_Animation.h"

#import "Masonry.h"

@interface Care_Animation()

@property(nonatomic,strong)UIImageView *ballView;

@end
@implementation Care_Animation

- (instancetype)initWithFrame:(CGRect)frame{
    
    if ( self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI{
    
    UIImageView * containerView =  [[UIImageView alloc]initWithFrame:self.frame];
    containerView.backgroundColor = [UIColor clearColor];
    UIImage *ballImage = [UIImage imageNamed:@"箭头"];
    self.ballView = [[UIImageView alloc]initWithImage:ballImage];
    [containerView addSubview:self.ballView];
    [self addSubview:containerView];
}
-(void)animate{
    
    self.ballView.center  = CGPointMake(-1, -1);
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
    animation.keyPath = @"position";
    animation.duration = 5.0;
    animation.repeatCount = INT_MAX;
    animation.delegate = self;
    animation.values = @[
                         [NSValue valueWithCGPoint:CGPointMake(150, 250)],
                         [NSValue valueWithCGPoint:CGPointMake(150, 268)],
                         [NSValue valueWithCGPoint:CGPointMake(150, 250)],
                         [NSValue valueWithCGPoint:CGPointMake(150, 268)],
                         [NSValue valueWithCGPoint:CGPointMake(150, 250)],
                         [NSValue valueWithCGPoint:CGPointMake(150, 268)],
                         [NSValue valueWithCGPoint:CGPointMake(150, 250)],
                         [NSValue valueWithCGPoint:CGPointMake(150, 268)]
                         ];
    
    animation.timingFunctions = @[
                                  [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseIn],
                                  [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut],
                                  [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseIn],
                                  [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut],
                                  [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseIn],
                                  [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut],
                                  [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseIn]
                                  ];
    animation.keyTimes = @[@0.0, @0.3, @0.5, @0.7, @0.8, @0.9, @0.95, @1.0];
    self.ballView.layer.position = CGPointMake(1, 1);
    [self.ballView.layer addAnimation:animation forKey:nil];
}
@end
